<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>下载班级</title>
    <script src="/sybida/common/js/locahostadress.js" charset="utf-8"></script>
    <link rel="stylesheet" href="/sybida/bs/bootstrap.min.css">
    <link rel="stylesheet" href="/sybida/layui/css/layui.css"  media="all">
    <script src="/sybida/common/js/xlsx.full.min.js" charset="utf-8"></script>
</head>
<body>
<div class="container">
    <div class="select" style="text-align: center;margin: 0 auto;" >
    <label class="classNum" style="line-height: 35px; font-size: 16px; ">选择班级</label><br/>
    <select class="form-control" id="classNum" style="width: 200px; display: inline-block;" >
    </select>
    <br/>
    <!--<button type="button" id="downloadbtn" class="btn btn-success" style="width: 200px;">下载</button>-->
        <a href="#" id="abtn" style="display:inline-block;width: 200px; margin-top: 2%"class="btn btn-success">下载文件</a>
    </div>
</div>
<script src="/sybida/jquery/jquery-3.3.1.min.js"></script>
<script src="/sybida/layui/layui.js"></script>
<script src="/sybida/bs/bootstrap.min.js"></script>
<script>
    var userid=getCookie("userid")
    var selectClass=1
    $.getJSON({
        url:url+"/classInfo/selectClass",
        beforeSend: function(request) {
            request.setRequestHeader("token", userid);
        },
        success:function (data) {
            if(data== -1000){
                location.href=logindexurl
            }else{
                var html=`<option value="-1">请选择班级</option>`
                for (let i = 0; i < data.length; i++) {
                    html += `<option value="${data[i].classId}">${data[i].classNum}</option>`
                }
                $('#classNum').append(html);
                var selectA1 = $('#classNum').find("option"); //从A1下拉框中 搜索值
                $(selectA1[0]).attr("selected","selected")
      //change事件
                $('#classNum').change(
                    function (){
                        selectClass=$('#classNum').val()
                    }
                )

                $("#abtn").click(function () {
                    console.log("-=-=-========================")
                    $.getJSON({
                        url: url+"/teacher/selectstudentclassid",
                        data:"classId="+selectClass,
                        beforeSend: function(request) {
                            request.setRequestHeader("token", userid);
                        },
                        success:function (data) {
                            if(data== -1000){
                                location.href=logindexurl
                            }else{
                                if (data.code==1){
                                    var beforeData = data.data
                                    let fields=["学生ID","学生姓名","学生性别","身份证号","是否毕业","毕业学校","专业",
                                        "学生微信","邮箱","学习方向","就业城市","家庭住址","家长电话","家长姓名","紧急电话",
                                        "学生电话","学生班级","学生寝室","学生头像","修改时间","评级","是否删除"]
                                    let afterData = beforeData.map((item)=>{
                                        return{
                                            "学生ID" : item.studentId, "学生姓名":item.studentName,
                                            "学生性别":item.studentSex,"身份证号":item.studentIdentity,
                                            "是否毕业":item.studentIsGraduation,"毕业学校":item.studentSchool,
                                            "专业":item.studentSpecialty,"学生微信":item.studentWechat,
                                            "邮箱":item.studentMailbox,"学习方向":item.studentStudyId,
                                            "就业城市":item.studentCity,"家庭住址":item.studentAddress,
                                            "家长电话":item.studentParentPhone,"家长姓名":item.studentParentName,
                                            "紧急电话":item.studentUrgent,"学生电话":item.studentPhone,
                                            "学生班级":item.studentClassId,"学生寝室":item.studentRoom,
                                            "学生头像":item.studentPhoto,"修改时间":item.studentAlterTime,
                                            "修改时间":item.studentAlterTime,"评级":item.studentNull1,
                                            "是否删除":item.studentNull2
                                        }
                                    })
                                    if (typeof XLSX == 'undefined') XLSX = require('xlsx');
                                    let ws = XLSX.utils.json_to_sheet(afterData);
                                    let wb = XLSX.utils.book_new();
                                    XLSX.utils.book_append_sheet(wb, ws, "People");
                                    XLSX.writeFile(wb, "学生" + ".xlsx");
                                }
                            }
                        }
                    })
                })
            }
    }});

</script>
</body>
</html>